<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE MagicHash #-}</span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ &gt;= 703
</span><span class="hs-pragma">{-# LANGUAGE Unsafe #-}</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- Module      : Data.ByteString.Unsafe</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Copyright   : (c) Don Stewart 2006-2008</span><span>
</span><span id="line-10"></span><span class="hs-comment">--               (c) Duncan Coutts 2006-2011</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- License     : BSD-style</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Maintainer  : dons00@gmail.com, duncan@community.haskell.org</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Stability   : provisional</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Portability : non-portable</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- A module containing unsafe 'ByteString' operations.</span><span>
</span><span id="line-17"></span><span class="hs-comment">--</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- While these functions have a stable API and you may use these functions in</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- applications, do carefully consider the documented pre-conditions;</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- incorrect use can break referential transparency or worse.</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.ByteString.Unsafe</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span>        </span><span class="annot"><span class="hs-comment">-- * Unchecked access</span></span><span>
</span><span id="line-25"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeHead"><span class="hs-identifier">unsafeHead</span></a></span><span class="hs-special">,</span><span>             </span><span class="hs-comment">-- :: ByteString -&gt; Word8</span><span>
</span><span id="line-26"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeTail"><span class="hs-identifier">unsafeTail</span></a></span><span class="hs-special">,</span><span>             </span><span class="hs-comment">-- :: ByteString -&gt; ByteString</span><span>
</span><span id="line-27"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeInit"><span class="hs-identifier">unsafeInit</span></a></span><span class="hs-special">,</span><span>             </span><span class="hs-comment">-- :: ByteString -&gt; ByteString</span><span>
</span><span id="line-28"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeLast"><span class="hs-identifier">unsafeLast</span></a></span><span class="hs-special">,</span><span>             </span><span class="hs-comment">-- :: ByteString -&gt; Word8</span><span>
</span><span id="line-29"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeIndex"><span class="hs-identifier">unsafeIndex</span></a></span><span class="hs-special">,</span><span>            </span><span class="hs-comment">-- :: ByteString -&gt; Int -&gt; Word8</span><span>
</span><span id="line-30"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeTake"><span class="hs-identifier">unsafeTake</span></a></span><span class="hs-special">,</span><span>             </span><span class="hs-comment">-- :: Int -&gt; ByteString -&gt; ByteString</span><span>
</span><span id="line-31"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeDrop"><span class="hs-identifier">unsafeDrop</span></a></span><span class="hs-special">,</span><span>             </span><span class="hs-comment">-- :: Int -&gt; ByteString -&gt; ByteString</span><span>
</span><span id="line-32"></span><span>
</span><span id="line-33"></span><span>        </span><span class="annot"><span class="hs-comment">-- * Low level interaction with CStrings</span></span><span>
</span><span id="line-34"></span><span>        </span><span class="annot"><span class="hs-comment">-- ** Using ByteStrings with functions for CStrings</span></span><span>
</span><span id="line-35"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeUseAsCString"><span class="hs-identifier">unsafeUseAsCString</span></a></span><span class="hs-special">,</span><span>     </span><span class="hs-comment">-- :: ByteString -&gt; (CString -&gt; IO a) -&gt; IO a</span><span>
</span><span id="line-36"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeUseAsCStringLen"><span class="hs-identifier">unsafeUseAsCStringLen</span></a></span><span class="hs-special">,</span><span>  </span><span class="hs-comment">-- :: ByteString -&gt; (CStringLen -&gt; IO a) -&gt; IO a</span><span>
</span><span id="line-37"></span><span>
</span><span id="line-38"></span><span>        </span><span class="annot"><span class="hs-comment">-- ** Converting CStrings to ByteStrings</span></span><span>
</span><span id="line-39"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackCString"><span class="hs-identifier">unsafePackCString</span></a></span><span class="hs-special">,</span><span>      </span><span class="hs-comment">-- :: CString -&gt; IO ByteString</span><span>
</span><span id="line-40"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackCStringLen"><span class="hs-identifier">unsafePackCStringLen</span></a></span><span class="hs-special">,</span><span>   </span><span class="hs-comment">-- :: CStringLen -&gt; IO ByteString</span><span>
</span><span id="line-41"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackMallocCString"><span class="hs-identifier">unsafePackMallocCString</span></a></span><span class="hs-special">,</span><span class="hs-comment">-- :: CString -&gt; IO ByteString</span><span>
</span><span id="line-42"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackMallocCStringLen"><span class="hs-identifier">unsafePackMallocCStringLen</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-comment">-- :: CStringLen -&gt; IO ByteString</span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span>        </span><span class="annot"><a href="Data.ByteString.Internal.html#unsafePackAddress"><span class="hs-identifier">unsafePackAddress</span></a></span><span class="hs-special">,</span><span>          </span><span class="hs-comment">-- :: Addr# -&gt; IO ByteString</span><span>
</span><span id="line-45"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackAddressLen"><span class="hs-identifier">unsafePackAddressLen</span></a></span><span class="hs-special">,</span><span>       </span><span class="hs-comment">-- :: Int -&gt; Addr# -&gt; IO ByteString</span><span>
</span><span id="line-46"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackCStringFinalizer"><span class="hs-identifier">unsafePackCStringFinalizer</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-comment">-- :: Ptr Word8 -&gt; Int -&gt; IO () -&gt; IO ByteString</span><span>
</span><span id="line-47"></span><span>        </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeFinalize"><span class="hs-identifier">unsafeFinalize</span></a></span><span class="hs-special">,</span><span>             </span><span class="hs-comment">-- :: ByteString -&gt; IO ()</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-50"></span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html"><span class="hs-identifier">Data.ByteString.Internal</span></a></span><span>
</span><span id="line-52"></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.ForeignPtr.html#"><span class="hs-identifier">Foreign.ForeignPtr</span></a></span><span>       </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.ForeignPtr.html#newForeignPtr_"><span class="hs-identifier">newForeignPtr_</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/Foreign.ForeignPtr.Imp.html#newForeignPtr"><span class="hs-identifier">newForeignPtr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier">withForeignPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.Ptr.html#"><span class="hs-identifier">Foreign.Ptr</span></a></span><span>              </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier">Ptr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-identifier">plusPtr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#castPtr"><span class="hs-identifier">castPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-55"></span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.Storable.html#"><span class="hs-identifier">Foreign.Storable</span></a></span><span>         </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.Storable.html#Storable"><span class="hs-identifier">Storable</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.String.html#"><span class="hs-identifier">Foreign.C.String</span></a></span><span>         </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.C.String.html#CString"><span class="hs-identifier">CString</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.String.html#CStringLen"><span class="hs-identifier">CStringLen</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Exception.html#"><span class="hs-identifier">Control.Exception</span></a></span><span>        </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Base.html#assert"><span class="hs-identifier">assert</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-60"></span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Word.html#"><span class="hs-identifier">Data.Word</span></a></span><span>                </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../base/src/Foreign.ForeignPtr.html#"><span class="hs-identifier">Foreign.ForeignPtr</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">FC</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.ForeignPtr.html#finalizeForeignPtr"><span class="hs-identifier">finalizeForeignPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../base/src/Foreign.Concurrent.html#"><span class="hs-identifier">Foreign.Concurrent</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">FC</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.Concurrent.html#newForeignPtr"><span class="hs-identifier">newForeignPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-65"></span><span>
</span><span id="line-66"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#"><span class="hs-identifier">GHC.Prim</span></a></span><span>                 </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#Addr%23"><span class="hs-identifier">Addr#</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-67"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#"><span class="hs-identifier">GHC.Ptr</span></a></span><span>                  </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier">Ptr</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span class="hs-comment">-- ---------------------------------------------------------------------</span><span>
</span><span id="line-70"></span><span class="hs-comment">--</span><span>
</span><span id="line-71"></span><span class="hs-comment">-- Extensions to the basic interface</span><span>
</span><span id="line-72"></span><span class="hs-comment">--</span><span>
</span><span id="line-73"></span><span>
</span><span id="line-74"></span><span class="hs-comment">-- | A variety of 'head' for non-empty ByteStrings. 'unsafeHead' omits the</span><span>
</span><span id="line-75"></span><span class="hs-comment">-- check for the empty case, so there is an obligation on the programmer</span><span>
</span><span id="line-76"></span><span class="hs-comment">-- to provide a proof that the ByteString is non-empty.</span><span>
</span><span id="line-77"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeHead"><span class="hs-identifier hs-type">unsafeHead</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-78"></span><span id="unsafeHead"><span class="annot"><span class="annottext">unsafeHead :: ByteString -&gt; Word8
</span><a href="Data.ByteString.Unsafe.html#unsafeHead"><span class="hs-identifier hs-var hs-var">unsafeHead</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072505"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072505"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679072504"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072504"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679072503"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072503"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Word8 -&gt; Word8
forall a. (?callStack::CallStack) =&gt; Bool -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#assert"><span class="hs-identifier hs-var hs-var">assert</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072503"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(Word8 -&gt; Word8) -&gt; Word8 -&gt; Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-79"></span><span>    </span><span class="annot"><span class="annottext">IO Word8 -&gt; Word8
forall a. IO a -&gt; a
</span><a href="Data.ByteString.Internal.html#accursedUnutterablePerformIO"><span class="hs-identifier hs-var">accursedUnutterablePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Word8 -&gt; Word8) -&gt; IO Word8 -&gt; Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; (Ptr Word8 -&gt; IO Word8) -&gt; IO Word8
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072505"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO Word8) -&gt; IO Word8)
-&gt; (Ptr Word8 -&gt; IO Word8) -&gt; IO Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679072500"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072500"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; IO Word8
forall a b. Storable a =&gt; Ptr b -&gt; Int -&gt; IO a
</span><a href="../../base/src/Foreign.Storable.html#peekByteOff"><span class="hs-identifier hs-var">peekByteOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072500"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072504"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-80"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeHead"><span class="hs-pragma hs-type">unsafeHead</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-81"></span><span>
</span><span id="line-82"></span><span class="hs-comment">-- | A variety of 'tail' for non-empty ByteStrings. 'unsafeTail' omits the</span><span>
</span><span id="line-83"></span><span class="hs-comment">-- check for the empty case. As with 'unsafeHead', the programmer must</span><span>
</span><span id="line-84"></span><span class="hs-comment">-- provide a separate proof that the ByteString is non-empty.</span><span>
</span><span id="line-85"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeTail"><span class="hs-identifier hs-type">unsafeTail</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-86"></span><span id="unsafeTail"><span class="annot"><span class="annottext">unsafeTail :: ByteString -&gt; ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafeTail"><span class="hs-identifier hs-var hs-var">unsafeTail</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072498"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072498"><span class="hs-identifier hs-var">ps</span></a></span></span><span> </span><span id="local-6989586621679072497"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072497"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679072496"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072496"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; ByteString -&gt; ByteString
forall a. (?callStack::CallStack) =&gt; Bool -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#assert"><span class="hs-identifier hs-var hs-var">assert</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072496"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; ByteString) -&gt; ByteString -&gt; ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072498"><span class="hs-identifier hs-var">ps</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072497"><span class="hs-identifier hs-var">s</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072496"><span class="hs-identifier hs-var">l</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-87"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeTail"><span class="hs-pragma hs-type">unsafeTail</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span class="hs-comment">-- | A variety of 'init' for non-empty ByteStrings. 'unsafeInit' omits the</span><span>
</span><span id="line-90"></span><span class="hs-comment">-- check for the empty case. As with 'unsafeHead', the programmer must</span><span>
</span><span id="line-91"></span><span class="hs-comment">-- provide a separate proof that the ByteString is non-empty.</span><span>
</span><span id="line-92"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeInit"><span class="hs-identifier hs-type">unsafeInit</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-93"></span><span id="unsafeInit"><span class="annot"><span class="annottext">unsafeInit :: ByteString -&gt; ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafeInit"><span class="hs-identifier hs-var hs-var">unsafeInit</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072494"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072494"><span class="hs-identifier hs-var">ps</span></a></span></span><span> </span><span id="local-6989586621679072493"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072493"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679072492"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072492"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; ByteString -&gt; ByteString
forall a. (?callStack::CallStack) =&gt; Bool -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#assert"><span class="hs-identifier hs-var hs-var">assert</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072492"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; ByteString) -&gt; ByteString -&gt; ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072494"><span class="hs-identifier hs-var">ps</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072493"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072492"><span class="hs-identifier hs-var">l</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-94"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeInit"><span class="hs-pragma hs-type">unsafeInit</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span class="hs-comment">-- | A variety of 'last' for non-empty ByteStrings. 'unsafeLast' omits the</span><span>
</span><span id="line-97"></span><span class="hs-comment">-- check for the empty case. As with 'unsafeHead', the programmer must</span><span>
</span><span id="line-98"></span><span class="hs-comment">-- provide a separate proof that the ByteString is non-empty.</span><span>
</span><span id="line-99"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeLast"><span class="hs-identifier hs-type">unsafeLast</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-100"></span><span id="unsafeLast"><span class="annot"><span class="annottext">unsafeLast :: ByteString -&gt; Word8
</span><a href="Data.ByteString.Unsafe.html#unsafeLast"><span class="hs-identifier hs-var hs-var">unsafeLast</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072491"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072491"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679072490"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072490"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679072489"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072489"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Word8 -&gt; Word8
forall a. (?callStack::CallStack) =&gt; Bool -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#assert"><span class="hs-identifier hs-var hs-var">assert</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072489"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(Word8 -&gt; Word8) -&gt; Word8 -&gt; Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-101"></span><span>    </span><span class="annot"><span class="annottext">IO Word8 -&gt; Word8
forall a. IO a -&gt; a
</span><a href="Data.ByteString.Internal.html#accursedUnutterablePerformIO"><span class="hs-identifier hs-var">accursedUnutterablePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Word8 -&gt; Word8) -&gt; IO Word8 -&gt; Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; (Ptr Word8 -&gt; IO Word8) -&gt; IO Word8
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072491"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO Word8) -&gt; IO Word8)
-&gt; (Ptr Word8 -&gt; IO Word8) -&gt; IO Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679072488"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072488"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; IO Word8
forall a b. Storable a =&gt; Ptr b -&gt; Int -&gt; IO a
</span><a href="../../base/src/Foreign.Storable.html#peekByteOff"><span class="hs-identifier hs-var">peekByteOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072488"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072490"><span class="hs-identifier hs-var">s</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072489"><span class="hs-identifier hs-var">l</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-102"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeLast"><span class="hs-pragma hs-type">unsafeLast</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-103"></span><span>
</span><span id="line-104"></span><span class="hs-comment">-- | Unsafe 'ByteString' index (subscript) operator, starting from 0, returning a 'Word8'</span><span>
</span><span id="line-105"></span><span class="hs-comment">-- This omits the bounds check, which means there is an accompanying</span><span>
</span><span id="line-106"></span><span class="hs-comment">-- obligation on the programmer to ensure the bounds are checked in some</span><span>
</span><span id="line-107"></span><span class="hs-comment">-- other way.</span><span>
</span><span id="line-108"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeIndex"><span class="hs-identifier hs-type">unsafeIndex</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-109"></span><span id="unsafeIndex"><span class="annot"><span class="annottext">unsafeIndex :: ByteString -&gt; Int -&gt; Word8
</span><a href="Data.ByteString.Unsafe.html#unsafeIndex"><span class="hs-identifier hs-var hs-var">unsafeIndex</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072487"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072487"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679072486"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072486"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679072485"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072485"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679072484"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072484"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Word8 -&gt; Word8
forall a. (?callStack::CallStack) =&gt; Bool -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#assert"><span class="hs-identifier hs-var hs-var">assert</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072484"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E%3D"><span class="hs-operator hs-var">&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072484"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072485"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(Word8 -&gt; Word8) -&gt; Word8 -&gt; Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-110"></span><span>    </span><span class="annot"><span class="annottext">IO Word8 -&gt; Word8
forall a. IO a -&gt; a
</span><a href="Data.ByteString.Internal.html#accursedUnutterablePerformIO"><span class="hs-identifier hs-var">accursedUnutterablePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Word8 -&gt; Word8) -&gt; IO Word8 -&gt; Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; (Ptr Word8 -&gt; IO Word8) -&gt; IO Word8
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072487"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO Word8) -&gt; IO Word8)
-&gt; (Ptr Word8 -&gt; IO Word8) -&gt; IO Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679072481"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072481"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; IO Word8
forall a b. Storable a =&gt; Ptr b -&gt; Int -&gt; IO a
</span><a href="../../base/src/Foreign.Storable.html#peekByteOff"><span class="hs-identifier hs-var">peekByteOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072481"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072486"><span class="hs-identifier hs-var">s</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072484"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-111"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeIndex"><span class="hs-pragma hs-type">unsafeIndex</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-112"></span><span>
</span><span id="line-113"></span><span class="hs-comment">-- | A variety of 'take' which omits the checks on @n@ so there is an</span><span>
</span><span id="line-114"></span><span class="hs-comment">-- obligation on the programmer to provide a proof that @0 &lt;= n &lt;= 'length' xs@.</span><span>
</span><span id="line-115"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeTake"><span class="hs-identifier hs-type">unsafeTake</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-116"></span><span id="unsafeTake"><span class="annot"><span class="annottext">unsafeTake :: Int -&gt; ByteString -&gt; ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafeTake"><span class="hs-identifier hs-var hs-var">unsafeTake</span></a></span></span><span> </span><span id="local-6989586621679072480"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072480"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072479"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072479"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679072478"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072478"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679072477"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072477"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; ByteString -&gt; ByteString
forall a. (?callStack::CallStack) =&gt; Bool -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#assert"><span class="hs-identifier hs-var hs-var">assert</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072480"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072480"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072477"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; ByteString) -&gt; ByteString -&gt; ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072479"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072478"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072480"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-117"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeTake"><span class="hs-pragma hs-type">unsafeTake</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-118"></span><span>
</span><span id="line-119"></span><span class="hs-comment">-- | A variety of 'drop' which omits the checks on @n@ so there is an</span><span>
</span><span id="line-120"></span><span class="hs-comment">-- obligation on the programmer to provide a proof that @0 &lt;= n &lt;= 'length' xs@.</span><span>
</span><span id="line-121"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeDrop"><span class="hs-identifier hs-type">unsafeDrop</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-122"></span><span id="unsafeDrop"><span class="annot"><span class="annottext">unsafeDrop :: Int -&gt; ByteString -&gt; ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafeDrop"><span class="hs-identifier hs-var hs-var">unsafeDrop</span></a></span></span><span> </span><span id="local-6989586621679072475"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072475"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072474"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072474"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679072473"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072473"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679072472"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072472"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; ByteString -&gt; ByteString
forall a. (?callStack::CallStack) =&gt; Bool -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#assert"><span class="hs-identifier hs-var hs-var">assert</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072475"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072475"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072472"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; ByteString) -&gt; ByteString -&gt; ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072474"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072473"><span class="hs-identifier hs-var">s</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072475"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072472"><span class="hs-identifier hs-var">l</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072475"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-123"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeDrop"><span class="hs-pragma hs-type">unsafeDrop</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-124"></span><span>
</span><span id="line-125"></span><span>
</span><span id="line-126"></span><span class="hs-comment">-- | /O(1)/ 'unsafePackAddressLen' provides constant-time construction of</span><span>
</span><span id="line-127"></span><span class="hs-comment">-- 'ByteString's, which is ideal for string literals. It packs a sequence</span><span>
</span><span id="line-128"></span><span class="hs-comment">-- of bytes into a 'ByteString', given a raw 'Addr#' to the string, and</span><span>
</span><span id="line-129"></span><span class="hs-comment">-- the length of the string.</span><span>
</span><span id="line-130"></span><span class="hs-comment">--</span><span>
</span><span id="line-131"></span><span class="hs-comment">-- This function is /unsafe/ in two ways:</span><span>
</span><span id="line-132"></span><span class="hs-comment">--</span><span>
</span><span id="line-133"></span><span class="hs-comment">-- * the length argument is assumed to be correct. If the length</span><span>
</span><span id="line-134"></span><span class="hs-comment">-- argument is incorrect, it is possible to overstep the end of the</span><span>
</span><span id="line-135"></span><span class="hs-comment">-- byte array.</span><span>
</span><span id="line-136"></span><span class="hs-comment">--</span><span>
</span><span id="line-137"></span><span class="hs-comment">-- * if the underlying 'Addr#' is later modified, this change will be</span><span>
</span><span id="line-138"></span><span class="hs-comment">-- reflected in the resulting 'ByteString', breaking referential</span><span>
</span><span id="line-139"></span><span class="hs-comment">-- transparency.</span><span>
</span><span id="line-140"></span><span class="hs-comment">--</span><span>
</span><span id="line-141"></span><span class="hs-comment">-- If in doubt, don't use this function.</span><span>
</span><span id="line-142"></span><span class="hs-comment">--</span><span>
</span><span id="line-143"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackAddressLen"><span class="hs-identifier hs-type">unsafePackAddressLen</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#Addr%23"><span class="hs-identifier hs-type">Addr#</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-144"></span><span id="unsafePackAddressLen"><span class="annot"><span class="annottext">unsafePackAddressLen :: Int -&gt; Addr# -&gt; IO ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafePackAddressLen"><span class="hs-identifier hs-var hs-var">unsafePackAddressLen</span></a></span></span><span> </span><span id="local-6989586621679072471"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072471"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span id="local-6989586621679072470"><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679072470"><span class="hs-identifier hs-var">addr#</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-145"></span><span>    </span><span id="local-6989586621679072469"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072469"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO (ForeignPtr Word8)
forall a. Ptr a -&gt; IO (ForeignPtr a)
</span><a href="../../base/src/GHC.ForeignPtr.html#newForeignPtr_"><span class="hs-identifier hs-var">newForeignPtr_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Addr# -&gt; Ptr Word8
forall a. Addr# -&gt; Ptr a
</span><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-var">Ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679072470"><span class="hs-identifier hs-var">addr#</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-146"></span><span>    </span><span class="annot"><span class="annottext">ByteString -&gt; IO ByteString
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; IO ByteString) -&gt; ByteString -&gt; IO ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072469"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072471"><span class="hs-identifier hs-var">len</span></a></span><span>
</span><span id="line-147"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackAddressLen"><span class="hs-pragma hs-type">unsafePackAddressLen</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-148"></span><span>
</span><span id="line-149"></span><span class="hs-comment">-- | /O(1)/ Construct a 'ByteString' given a Ptr Word8 to a buffer, a</span><span>
</span><span id="line-150"></span><span class="hs-comment">-- length, and an IO action representing a finalizer. This function is</span><span>
</span><span id="line-151"></span><span class="hs-comment">-- not available on Hugs.</span><span>
</span><span id="line-152"></span><span class="hs-comment">--</span><span>
</span><span id="line-153"></span><span class="hs-comment">-- This function is /unsafe/, it is possible to break referential</span><span>
</span><span id="line-154"></span><span class="hs-comment">-- transparency by modifying the underlying buffer pointed to by the</span><span>
</span><span id="line-155"></span><span class="hs-comment">-- first argument. Any changes to the original buffer will be reflected</span><span>
</span><span id="line-156"></span><span class="hs-comment">-- in the resulting 'ByteString'.</span><span>
</span><span id="line-157"></span><span class="hs-comment">--</span><span>
</span><span id="line-158"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackCStringFinalizer"><span class="hs-identifier hs-type">unsafePackCStringFinalizer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-159"></span><span id="unsafePackCStringFinalizer"><span class="annot"><span class="annottext">unsafePackCStringFinalizer :: Ptr Word8 -&gt; Int -&gt; IO () -&gt; IO ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafePackCStringFinalizer"><span class="hs-identifier hs-var hs-var">unsafePackCStringFinalizer</span></a></span></span><span> </span><span id="local-6989586621679072467"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072467"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span id="local-6989586621679072466"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072466"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span id="local-6989586621679072465"><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679072465"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-160"></span><span>    </span><span id="local-6989586621679072464"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072464"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO () -&gt; IO (ForeignPtr Word8)
forall a. Ptr a -&gt; IO () -&gt; IO (ForeignPtr a)
</span><a href="../../base/src/Foreign.Concurrent.html#newForeignPtr"><span class="hs-identifier hs-var">FC.newForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072467"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679072465"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-161"></span><span>    </span><span class="annot"><span class="annottext">ByteString -&gt; IO ByteString
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; IO ByteString) -&gt; ByteString -&gt; IO ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072464"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072466"><span class="hs-identifier hs-var">l</span></a></span><span>
</span><span id="line-162"></span><span>
</span><span id="line-163"></span><span class="hs-comment">-- | Explicitly run the finaliser associated with a 'ByteString'.</span><span>
</span><span id="line-164"></span><span class="hs-comment">-- References to this value after finalisation may generate invalid memory</span><span>
</span><span id="line-165"></span><span class="hs-comment">-- references.</span><span>
</span><span id="line-166"></span><span class="hs-comment">--</span><span>
</span><span id="line-167"></span><span class="hs-comment">-- This function is /unsafe/, as there may be other</span><span>
</span><span id="line-168"></span><span class="hs-comment">-- 'ByteString's referring to the same underlying pages. If you use</span><span>
</span><span id="line-169"></span><span class="hs-comment">-- this, you need to have a proof of some kind that all 'ByteString's</span><span>
</span><span id="line-170"></span><span class="hs-comment">-- ever generated from the underlying byte array are no longer live.</span><span>
</span><span id="line-171"></span><span class="hs-comment">--</span><span>
</span><span id="line-172"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeFinalize"><span class="hs-identifier hs-type">unsafeFinalize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-173"></span><span id="unsafeFinalize"><span class="annot"><span class="annottext">unsafeFinalize :: ByteString -&gt; IO ()
</span><a href="Data.ByteString.Unsafe.html#unsafeFinalize"><span class="hs-identifier hs-var hs-var">unsafeFinalize</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072463"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072463"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; IO ()
forall a. ForeignPtr a -&gt; IO ()
</span><a href="../../base/src/GHC.ForeignPtr.html#finalizeForeignPtr"><span class="hs-identifier hs-var">FC.finalizeForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072463"><span class="hs-identifier hs-var">p</span></a></span><span>
</span><span id="line-174"></span><span>
</span><span id="line-175"></span><span class="hs-comment">------------------------------------------------------------------------</span><span>
</span><span id="line-176"></span><span class="hs-comment">-- Packing CStrings into ByteStrings</span><span>
</span><span id="line-177"></span><span>
</span><span id="line-178"></span><span class="hs-comment">-- | /O(n)/ Build a 'ByteString' from a 'CString'. This value will have /no/</span><span>
</span><span id="line-179"></span><span class="hs-comment">-- finalizer associated to it, and will not be garbage collected by</span><span>
</span><span id="line-180"></span><span class="hs-comment">-- Haskell. The ByteString length is calculated using /strlen(3)/,</span><span>
</span><span id="line-181"></span><span class="hs-comment">-- and thus the complexity is a /O(n)/.</span><span>
</span><span id="line-182"></span><span class="hs-comment">--</span><span>
</span><span id="line-183"></span><span class="hs-comment">-- This function is /unsafe/. If the 'CString' is later modified, this</span><span>
</span><span id="line-184"></span><span class="hs-comment">-- change will be reflected in the resulting 'ByteString', breaking</span><span>
</span><span id="line-185"></span><span class="hs-comment">-- referential transparency.</span><span>
</span><span id="line-186"></span><span class="hs-comment">--</span><span>
</span><span id="line-187"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackCString"><span class="hs-identifier hs-type">unsafePackCString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-188"></span><span id="unsafePackCString"><span class="annot"><span class="annottext">unsafePackCString :: CString -&gt; IO ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafePackCString"><span class="hs-identifier hs-var hs-var">unsafePackCString</span></a></span></span><span> </span><span id="local-6989586621679072462"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072462"><span class="hs-identifier hs-var">cstr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-189"></span><span>    </span><span id="local-6989586621679072461"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072461"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO (ForeignPtr Word8)
forall a. Ptr a -&gt; IO (ForeignPtr a)
</span><a href="../../base/src/GHC.ForeignPtr.html#newForeignPtr_"><span class="hs-identifier hs-var">newForeignPtr_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CString -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072462"><span class="hs-identifier hs-var">cstr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-190"></span><span>    </span><span id="local-6989586621679072460"><span class="annot"><span class="annottext">CSize
</span><a href="#local-6989586621679072460"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CString -&gt; IO CSize
</span><a href="Data.ByteString.Internal.html#c_strlen"><span class="hs-identifier hs-var">c_strlen</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072462"><span class="hs-identifier hs-var">cstr</span></a></span><span>
</span><span id="line-191"></span><span>    </span><span class="annot"><span class="annottext">ByteString -&gt; IO ByteString
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; IO ByteString) -&gt; ByteString -&gt; IO ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072461"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CSize -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CSize
</span><a href="#local-6989586621679072460"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-192"></span><span>
</span><span id="line-193"></span><span class="hs-comment">-- | /O(1)/ Build a 'ByteString' from a 'CStringLen'. This value will</span><span>
</span><span id="line-194"></span><span class="hs-comment">-- have /no/ finalizer associated with it, and will not be garbage</span><span>
</span><span id="line-195"></span><span class="hs-comment">-- collected by Haskell. This operation has /O(1)/ complexity as we</span><span>
</span><span id="line-196"></span><span class="hs-comment">-- already know the final size, so no /strlen(3)/ is required.</span><span>
</span><span id="line-197"></span><span class="hs-comment">--</span><span>
</span><span id="line-198"></span><span class="hs-comment">-- This function is /unsafe/. If the original 'CStringLen' is later</span><span>
</span><span id="line-199"></span><span class="hs-comment">-- modified, this change will be reflected in the resulting 'ByteString',</span><span>
</span><span id="line-200"></span><span class="hs-comment">-- breaking referential transparency.</span><span>
</span><span id="line-201"></span><span class="hs-comment">--</span><span>
</span><span id="line-202"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackCStringLen"><span class="hs-identifier hs-type">unsafePackCStringLen</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-type">CStringLen</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-203"></span><span id="unsafePackCStringLen"><span class="annot"><span class="annottext">unsafePackCStringLen :: CStringLen -&gt; IO ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafePackCStringLen"><span class="hs-identifier hs-var hs-var">unsafePackCStringLen</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679072457"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072457"><span class="hs-identifier hs-var">ptr</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679072456"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072456"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-204"></span><span>    </span><span id="local-6989586621679072455"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072455"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO (ForeignPtr Word8)
forall a. Ptr a -&gt; IO (ForeignPtr a)
</span><a href="../../base/src/GHC.ForeignPtr.html#newForeignPtr_"><span class="hs-identifier hs-var">newForeignPtr_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CString -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072457"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-205"></span><span>    </span><span class="annot"><span class="annottext">ByteString -&gt; IO ByteString
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; IO ByteString) -&gt; ByteString -&gt; IO ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072455"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072456"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-206"></span><span>
</span><span id="line-207"></span><span class="hs-comment">-- | /O(n)/ Build a 'ByteString' from a malloced 'CString'. This value will</span><span>
</span><span id="line-208"></span><span class="hs-comment">-- have a @free(3)@ finalizer associated to it.</span><span>
</span><span id="line-209"></span><span class="hs-comment">--</span><span>
</span><span id="line-210"></span><span class="hs-comment">-- This function is /unsafe/. If the original 'CString' is later</span><span>
</span><span id="line-211"></span><span class="hs-comment">-- modified, this change will be reflected in the resulting 'ByteString',</span><span>
</span><span id="line-212"></span><span class="hs-comment">-- breaking referential transparency.</span><span>
</span><span id="line-213"></span><span class="hs-comment">--</span><span>
</span><span id="line-214"></span><span class="hs-comment">-- This function is also unsafe if you call its finalizer twice,</span><span>
</span><span id="line-215"></span><span class="hs-comment">-- which will result in a /double free/ error, or if you pass it</span><span>
</span><span id="line-216"></span><span class="hs-comment">-- a 'CString' not allocated with 'Foreign.Marshal.Alloc.malloc'.</span><span>
</span><span id="line-217"></span><span class="hs-comment">--</span><span>
</span><span id="line-218"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackMallocCString"><span class="hs-identifier hs-type">unsafePackMallocCString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-219"></span><span id="unsafePackMallocCString"><span class="annot"><span class="annottext">unsafePackMallocCString :: CString -&gt; IO ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafePackMallocCString"><span class="hs-identifier hs-var hs-var">unsafePackMallocCString</span></a></span></span><span> </span><span id="local-6989586621679072454"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072454"><span class="hs-identifier hs-var">cstr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-220"></span><span>    </span><span id="local-6989586621679072453"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072453"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FinalizerPtr Word8 -&gt; Ptr Word8 -&gt; IO (ForeignPtr Word8)
forall a. FinalizerPtr a -&gt; Ptr a -&gt; IO (ForeignPtr a)
</span><a href="../../base/src/Foreign.ForeignPtr.Imp.html#newForeignPtr"><span class="hs-identifier hs-var">newForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">FinalizerPtr Word8
</span><a href="Data.ByteString.Internal.html#c_free_finalizer"><span class="hs-identifier hs-var">c_free_finalizer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CString -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072454"><span class="hs-identifier hs-var">cstr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-221"></span><span>    </span><span id="local-6989586621679072451"><span class="annot"><span class="annottext">CSize
</span><a href="#local-6989586621679072451"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CString -&gt; IO CSize
</span><a href="Data.ByteString.Internal.html#c_strlen"><span class="hs-identifier hs-var">c_strlen</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072454"><span class="hs-identifier hs-var">cstr</span></a></span><span>
</span><span id="line-222"></span><span>    </span><span class="annot"><span class="annottext">ByteString -&gt; IO ByteString
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; IO ByteString) -&gt; ByteString -&gt; IO ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072453"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CSize -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CSize
</span><a href="#local-6989586621679072451"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-223"></span><span>
</span><span id="line-224"></span><span class="hs-comment">-- | /O(1)/ Build a 'ByteString' from a malloced 'CStringLen'. This</span><span>
</span><span id="line-225"></span><span class="hs-comment">-- value will have a @free(3)@ finalizer associated to it.</span><span>
</span><span id="line-226"></span><span class="hs-comment">--</span><span>
</span><span id="line-227"></span><span class="hs-comment">-- This function is /unsafe/. If the original 'CString' is later</span><span>
</span><span id="line-228"></span><span class="hs-comment">-- modified, this change will be reflected in the resulting 'ByteString',</span><span>
</span><span id="line-229"></span><span class="hs-comment">-- breaking referential transparency.</span><span>
</span><span id="line-230"></span><span class="hs-comment">--</span><span>
</span><span id="line-231"></span><span class="hs-comment">-- This function is also unsafe if you call its finalizer twice,</span><span>
</span><span id="line-232"></span><span class="hs-comment">-- which will result in a /double free/ error, or if you pass it</span><span>
</span><span id="line-233"></span><span class="hs-comment">-- a 'CString' not allocated with 'Foreign.Marshal.Alloc.malloc'.</span><span>
</span><span id="line-234"></span><span class="hs-comment">--</span><span>
</span><span id="line-235"></span><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafePackMallocCStringLen"><span class="hs-identifier hs-type">unsafePackMallocCStringLen</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-type">CStringLen</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span>
</span><span id="line-236"></span><span id="unsafePackMallocCStringLen"><span class="annot"><span class="annottext">unsafePackMallocCStringLen :: CStringLen -&gt; IO ByteString
</span><a href="Data.ByteString.Unsafe.html#unsafePackMallocCStringLen"><span class="hs-identifier hs-var hs-var">unsafePackMallocCStringLen</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679072450"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072450"><span class="hs-identifier hs-var">cstr</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679072449"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072449"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-237"></span><span>    </span><span id="local-6989586621679072448"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072448"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FinalizerPtr Word8 -&gt; Ptr Word8 -&gt; IO (ForeignPtr Word8)
forall a. FinalizerPtr a -&gt; Ptr a -&gt; IO (ForeignPtr a)
</span><a href="../../base/src/Foreign.ForeignPtr.Imp.html#newForeignPtr"><span class="hs-identifier hs-var">newForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">FinalizerPtr Word8
</span><a href="Data.ByteString.Internal.html#c_free_finalizer"><span class="hs-identifier hs-var">c_free_finalizer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CString -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679072450"><span class="hs-identifier hs-var">cstr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-238"></span><span>    </span><span class="annot"><span class="annottext">ByteString -&gt; IO ByteString
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; IO ByteString) -&gt; ByteString -&gt; IO ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072448"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072449"><span class="hs-identifier hs-var">len</span></a></span><span>
</span><span id="line-239"></span><span>
</span><span id="line-240"></span><span class="hs-comment">-- ---------------------------------------------------------------------</span><span>
</span><span id="line-241"></span><span>
</span><span id="line-242"></span><span class="hs-comment">-- | /O(1) construction/ Use a 'ByteString' with a function requiring a</span><span>
</span><span id="line-243"></span><span class="hs-comment">-- 'CString'.</span><span>
</span><span id="line-244"></span><span class="hs-comment">--</span><span>
</span><span id="line-245"></span><span class="hs-comment">-- This function does zero copying, and merely unwraps a 'ByteString' to</span><span>
</span><span id="line-246"></span><span class="hs-comment">-- appear as a 'CString'. It is /unsafe/ in two ways:</span><span>
</span><span id="line-247"></span><span class="hs-comment">--</span><span>
</span><span id="line-248"></span><span class="hs-comment">-- * After calling this function the 'CString' shares the underlying</span><span>
</span><span id="line-249"></span><span class="hs-comment">-- byte buffer with the original 'ByteString'. Thus modifying the</span><span>
</span><span id="line-250"></span><span class="hs-comment">-- 'CString', either in C, or using poke, will cause the contents of the</span><span>
</span><span id="line-251"></span><span class="hs-comment">-- 'ByteString' to change, breaking referential transparency. Other</span><span>
</span><span id="line-252"></span><span class="hs-comment">-- 'ByteString's created by sharing (such as those produced via 'take'</span><span>
</span><span id="line-253"></span><span class="hs-comment">-- or 'drop') will also reflect these changes. Modifying the 'CString'</span><span>
</span><span id="line-254"></span><span class="hs-comment">-- will break referential transparency. To avoid this, use</span><span>
</span><span id="line-255"></span><span class="hs-comment">-- 'Data.ByteString.useAsCString', which makes a copy of the original 'ByteString'.</span><span>
</span><span id="line-256"></span><span class="hs-comment">--</span><span>
</span><span id="line-257"></span><span class="hs-comment">-- * 'CString's are often passed to functions that require them to be</span><span>
</span><span id="line-258"></span><span class="hs-comment">-- null-terminated. If the original 'ByteString' wasn't null terminated,</span><span>
</span><span id="line-259"></span><span class="hs-comment">-- neither will the 'CString' be. It is the programmers responsibility</span><span>
</span><span id="line-260"></span><span class="hs-comment">-- to guarantee that the 'ByteString' is indeed null terminated. If in</span><span>
</span><span id="line-261"></span><span class="hs-comment">-- doubt, use 'Data.ByteString.useAsCString'.</span><span>
</span><span id="line-262"></span><span class="hs-comment">--</span><span>
</span><span id="line-263"></span><span class="hs-comment">-- * The memory may freed at any point after the subcomputation</span><span>
</span><span id="line-264"></span><span class="hs-comment">-- terminates, so the pointer to the storage must *not* be used</span><span>
</span><span id="line-265"></span><span class="hs-comment">-- after this.</span><span>
</span><span id="line-266"></span><span class="hs-comment">--</span><span>
</span><span id="line-267"></span><span id="local-6989586621679072608"><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeUseAsCString"><span class="hs-identifier hs-type">unsafeUseAsCString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679072608"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679072608"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-268"></span><span id="unsafeUseAsCString"><span class="annot"><span class="annottext">unsafeUseAsCString :: forall a. ByteString -&gt; (CString -&gt; IO a) -&gt; IO a
</span><a href="Data.ByteString.Unsafe.html#unsafeUseAsCString"><span class="hs-identifier hs-var hs-var">unsafeUseAsCString</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072447"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072447"><span class="hs-identifier hs-var">ps</span></a></span></span><span> </span><span id="local-6989586621679072446"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072446"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679072445"><span class="annot"><span class="annottext">CString -&gt; IO a
</span><a href="#local-6989586621679072445"><span class="hs-identifier hs-var">ac</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; (Ptr Word8 -&gt; IO a) -&gt; IO a
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072447"><span class="hs-identifier hs-var">ps</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO a) -&gt; IO a) -&gt; (Ptr Word8 -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679072444"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072444"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CString -&gt; IO a
</span><a href="#local-6989586621679072445"><span class="hs-identifier hs-var">ac</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Any
forall a b. Ptr a -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072444"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Any -&gt; Int -&gt; CString
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072446"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-269"></span><span>
</span><span id="line-270"></span><span class="hs-comment">-- | /O(1) construction/ Use a 'ByteString' with a function requiring a</span><span>
</span><span id="line-271"></span><span class="hs-comment">-- 'CStringLen'.</span><span>
</span><span id="line-272"></span><span class="hs-comment">--</span><span>
</span><span id="line-273"></span><span class="hs-comment">-- This function does zero copying, and merely unwraps a 'ByteString' to</span><span>
</span><span id="line-274"></span><span class="hs-comment">-- appear as a 'CStringLen'. It is /unsafe/:</span><span>
</span><span id="line-275"></span><span class="hs-comment">--</span><span>
</span><span id="line-276"></span><span class="hs-comment">-- * After calling this function the 'CStringLen' shares the underlying</span><span>
</span><span id="line-277"></span><span class="hs-comment">-- byte buffer with the original 'ByteString'. Thus modifying the</span><span>
</span><span id="line-278"></span><span class="hs-comment">-- 'CStringLen', either in C, or using poke, will cause the contents of the</span><span>
</span><span id="line-279"></span><span class="hs-comment">-- 'ByteString' to change, breaking referential transparency. Other</span><span>
</span><span id="line-280"></span><span class="hs-comment">-- 'ByteString's created by sharing (such as those produced via 'take'</span><span>
</span><span id="line-281"></span><span class="hs-comment">-- or 'drop') will also reflect these changes. Modifying the 'CStringLen'</span><span>
</span><span id="line-282"></span><span class="hs-comment">-- will break referential transparency. To avoid this, use</span><span>
</span><span id="line-283"></span><span class="hs-comment">-- 'Data.ByteString.useAsCStringLen', which makes a copy of the original 'ByteString'.</span><span>
</span><span id="line-284"></span><span class="hs-comment">--</span><span>
</span><span id="line-285"></span><span class="hs-comment">-- If 'Data.ByteString.empty' is given, it will pass @('Foreign.Ptr.nullPtr', 0)@.</span><span>
</span><span id="line-286"></span><span id="local-6989586621679072604"><span class="annot"><a href="Data.ByteString.Unsafe.html#unsafeUseAsCStringLen"><span class="hs-identifier hs-type">unsafeUseAsCStringLen</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-type">CStringLen</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679072604"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679072604"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-287"></span><span id="unsafeUseAsCStringLen"><span class="annot"><span class="annottext">unsafeUseAsCStringLen :: forall a. ByteString -&gt; (CStringLen -&gt; IO a) -&gt; IO a
</span><a href="Data.ByteString.Unsafe.html#unsafeUseAsCStringLen"><span class="hs-identifier hs-var hs-var">unsafeUseAsCStringLen</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">PS</span></a></span><span> </span><span id="local-6989586621679072443"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072443"><span class="hs-identifier hs-var">ps</span></a></span></span><span> </span><span id="local-6989586621679072442"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072442"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679072441"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072441"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679072440"><span class="annot"><span class="annottext">CStringLen -&gt; IO a
</span><a href="#local-6989586621679072440"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; (Ptr Word8 -&gt; IO a) -&gt; IO a
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679072443"><span class="hs-identifier hs-var">ps</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO a) -&gt; IO a) -&gt; (Ptr Word8 -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679072439"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072439"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CStringLen -&gt; IO a
</span><a href="#local-6989586621679072440"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Any
forall a b. Ptr a -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679072439"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Any -&gt; Int -&gt; CString
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072442"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679072441"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-288"></span></pre></body></html>